import { login, getUserInfoApi } from '@/api/user'
import { getStatsApi, getOrderApi, getIncomeApi, getHotlistApi, getSaleDataApi } from '@/api/dashboard'
export default {
  namespaced: true,
  state: {
    token: null,
    userId: null,
    userInfo: null,
    start: null,
    end: null,
    Stats: null,
    order: null,
    income: null,
    hotlist: null,
    series: null,
    xAxis: null,
  },
  mutations: {
    setToken(state, res) {
      state.token = res.token
      state.userId = res.userId
    },
    removeToken(state) {
      state.token = null
    },
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo
    },
    setTime(state, res) {
      state.start = res.start
      state.end = res.end
    },
    setStats(state, res) {
      state.Stats = res
    },
    setOrder(state, order) {
      state.order = order
    },
    setIncome(state, income) {
      state.income = income
    },
    setHotlist(state, hotlist) {
      state.hotlist = hotlist
    },
    setSaleData(state, res) {
      state.series = res.series
      state.xAxis = res.xAxis
    }
  },
  actions: {
    async loginAction({ commit }, data) {
      const res = await login(data)
      commit('setToken', res)
    },
    async getUserInfoAction({ commit }, data) {
      const res = await getUserInfoApi(data)
      console.log(res)
      commit('setUserInfo', res)
    },
    async getStatsAction({ commit }, data) {
      const res = await getStatsApi(data)
      commit('setStats', res)
    },
    async getOrderAction({ commit }, data) {
      const res = await getOrderApi(data)
      commit('setOrder', res)
    },
    async getIncomeAction({ commit }, data) {
      const res = await getIncomeApi(data)
      commit('setIncome', res)
    },
    async getHotlistAction({ commit }, data) {
      const res = await getHotlistApi(data.start, data.end)
      commit('setHotlist', res)
    },
    async getSaleDataAction({ commit }, data) {
      const res = await getSaleDataApi(data)
      commit('setSaleData', res)
    }
  }
}
